﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using BanditGame2.Classes;

namespace BanditGame2
{
    public partial class ChooseBonus : ChildWindow
    {
        

        public Bonus.bonus chosedBonus = Bonus.bonus.life;

        public ChooseBonus(int magazineSize, int bulletCount, int bullet1Count, int canonCount, int dynamiteCount, int speedUpCount)
        {
            InitializeComponent();

            MainPage parent = this.Parent as MainPage;

            int myInt = GetRandomInt((int) Bonus.bonus.life, (int) Bonus.bonus.hint );
            switch ((Bonus.bonus)myInt)
            {
                case Bonus.bonus.life:
                    {
                        radioA.Content = "Život";
                        radioA.Checked += delegate
                                              { chosedBonus = Bonus.bonus.life;
                                                  OKButton.IsEnabled = true;
                                              };
                        break;
                    }
                case Bonus.bonus.magazine:
                    {
                        radioA.Content = "Zvětšení zásobníku +1";
                        radioA.Checked += delegate
                        { chosedBonus = Bonus.bonus.magazine; OKButton.IsEnabled = true; };
                        break;
                    }
                case Bonus.bonus.hint:
                    {
                        radioA.Content = "Nápověda do další otázky";
                        radioA.Checked += delegate
                        { chosedBonus = Bonus.bonus.hint;
                        OKButton.IsEnabled = true;
                        };
                        break;
                    }
            }

            if(magazineSize>(speedUpCount + bullet1Count + bulletCount + canonCount + dynamiteCount))
            {
                radioB.IsEnabled = true;
                myInt = GetRandomInt((int) Bonus.bonus.bullet, (int) Bonus.bonus.speedUp );
                switch ((Bonus.bonus)myInt)
                {
                    case Bonus.bonus.bullet:
                        {
                            radioB.Content = "Střela";
                            radioB.Checked += delegate
                                                  { chosedBonus = Bonus.bonus.bullet;
                                                  OKButton.IsEnabled = true;
                                                  };
                            break;
                        }
                        case Bonus.bonus.bullet1:
                        {
                            radioB.Content = "Střela opakovačky";
                            radioB.Checked += delegate
                                                  { chosedBonus = BanditGame2.Classes.Bonus.bonus.bullet1;
                                                  OKButton.IsEnabled = true;
                                                  };
                            break;
                        }
                        case Bonus.bonus.canon:
                        {
                            radioB.Content = "Kanón";
                            radioB.Checked += delegate
                                                  { chosedBonus = Bonus.bonus.canon;
                                                  OKButton.IsEnabled = true;
                                                  };
                            break;
                        }
                        case Bonus.bonus.dynamite:
                        {
                            radioB.Content = "Dynamit";
                            radioB.Checked += delegate
                                { chosedBonus = BanditGame2.Classes.Bonus.bonus.dynamite;
                                OKButton.IsEnabled = true;
                                };
                            break;
                        }
                        case Bonus.bonus.speedUp:
                        {
                            radioB.Content = "Zrychlení";
                            radioB.Checked += delegate
                                                  { chosedBonus = Bonus.bonus.speedUp;
                                                  OKButton.IsEnabled = true;
                                                  };
                            break;
                        }
                }
            }
        }

        Random rnd = new Random();
        
        protected int GetRandomInt(int min, int max)
        {
            int i;
            i = rnd.Next(min, max+1);
            if(i<=max)
                return i;
            else
            {
                return i - 1;
            }
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }
    }
}

